package a8;

public class Longitude {


	  double lon; 
	  
	  public Longitude(double degLongitude) {
	    if (degLongitude > 180. || degLongitude < -180.)		//I will assume (-) is West and (+) is East.
	      throw new IllegalArgumentException("Longitude out of range");
	    this.lon = toRadians(degLongitude); 
	  }
	  
	  public Longitude(int deg, int min, double sec) {
	    this(deg + min / 60. + sec / 3600.);
	  } 
	  
	  private static double toRadians(double degLongitude) { 
	    return degLongitude * Math.PI / 180.;
	  }
	  
	  public double getDegLon() {
	    return this.lon * 180. / Math.PI;
	  }
		
	  public String getDMSLat() {
			int deg = 0;
			int min = 0;
			double sec = 0;

			deg = (int) lon;
			min = (int) ((lon - deg) * 60); 
			sec = ((lon - deg) * 60 - min) * 60;

			String time = String.format("%d\u00b0%d\'%.1f\"", deg, min, sec);
			return time;

		}

	  public double getLon() {
	    return lon;
	  }  
	  
}
